﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSqlServer;

public partial class ajax_topic_list : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string myuid = Request["myuid"].ToString();
            string pagenum = Request["pagenum"].ToString();
            mytopiclist.Text = GetTopics(pagenum, myuid);
        }
    }
    private string GetTopics(string pagenum,string myuid)
    {
        TUser oUser = new TUser(myuid);
        oUser.Select();

        string result = "<table border=0 align=left width=\"100%\"><tr><td><table width=\"100%\" id=\"mytopics\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" style='BORDER-COLLAPSE: collapse;font-size: 11pt;' bordercolor=\"#cfdfff\" align=\"left\">";

        result += "<thead>";
        result += "<tr height=30 style=\"background-color:#f5f5f5\">";
        result += "<td align=center class=\"tdtitle\">主&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题</td>";
        result += "<td align=center width=80 class=\"tdtitle\">发起人</td>";
        result += "<td align=center width=100 class=\"tdtitle\">发起时间</td>";
        result += "<td align=center width=100 class=\"tdtitle\">回复/点击</td>";
        result += "<td align=center></td>";
        result += "</tr>";
        result += "</thead>";

        result += "<tbody>";
        TBBSTopic oTopics = new TBBSTopic();
        oTopics.GetPage(Convert.ToInt32(pagenum));
        while (oTopics.RResults.Read())
        {
            DateTime topic_time = (DateTime)oTopics.RResults.GetValue(oTopics.RResults.GetOrdinal("topic_time"));

            result += "<tr height=28>";

            result += "<td nowrap style=\"font-size:11pt;\">·<a href=\"easybbs_topic.aspx?myuid=" + myuid + "&topicid=" + oTopics.RResults.GetValue(oTopics.RResults.GetOrdinal("topic_id")).ToString() + "\" target=_blank>" + oTopics.RResults.GetValue(oTopics.RResults.GetOrdinal("topic_title")).ToString() + "</a>";

            TimeSpan ts = DateTime.Today - topic_time;
            if (ts.TotalDays < 7)
            {
                result += "<img src=\"./images/new01.gif\" border=0></td>";
            }
            else
            {
                result += "</td>";
            }

            result += "<td width=80 align=center nowrap style=\"font-size:11pt;\">" + oTopics.RResults.GetValue(oTopics.RResults.GetOrdinal("topic_author")).ToString() + "</td>";
            result += "<td width=100 align=center nowrap style=\"font-size:11pt;\">" + topic_time.ToString("yy-MM-dd HH:mm") + "</td>";
            result += "<td width=100 align=center nowrap style=\"font-size:11pt;\">" + oTopics.RResults.GetValue(oTopics.RResults.GetOrdinal("topic_forums")).ToString() + " / " + oTopics.RResults.GetValue(oTopics.RResults.GetOrdinal("topic_hit")).ToString() + "</td>";

            if (oTopics.RResults.GetValue(oTopics.RResults.GetOrdinal("topic_author")).ToString() == oUser.BigName)
            {
                if (Convert.ToInt32(oTopics.RResults.GetValue(oTopics.RResults.GetOrdinal("topic_forums")).ToString())==0)
                {
                    result += "<td><span onclick=\"deltopic('" + oTopics.RResults.GetValue(oTopics.RResults.GetOrdinal("topic_id")).ToString() + "')\" style=\"cursor:hand;\"><img src=\"./images/del.gif\" border=0></span></td>";
                }
                else
                {
                    result += "<td>&nbsp;</td>";
                }
            }
            else
            {
                result += "<td>&nbsp;</td>";
            }

            result += "</tr>";
        }
        result += "</tbody>";

        result += "</table></td></tr><tr><td>";

        result += oTopics.GenPagebar(Convert.ToInt32(pagenum)) + "</td></tr></table>";

        return result;
    }
}
